package top.jiangqiang.qyblog.admin.controller;

import cn.hutool.extra.pinyin.PinyinUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import top.jiangqiang.qyblog.common.base.controller.BaseController;
import top.jiangqiang.qyblog.common.base.response.Result;
import top.jiangqiang.qyblog.common.constant.RequestURLConstants;
import top.jiangqiang.qyblog.common.utils.MarkdownUtils;
import top.jiangqiang.qyblog.core.domain.dto.MarkdownDto;

/**
 * @author jiangqiang
 * @date 2022-07-10
 */
@RequiredArgsConstructor
@RestController
@RequestMapping(RequestURLConstants.COMMON_CONTROLLER_PREFIX)
@Tag(name = "公共接口")
public class CommonController extends BaseController {

    @PostMapping("/renderMarkdown")
    @Operation(summary = "渲染Markdown文本", description = "渲染markdown文本")
    public Result<String> renderMarkdown(@RequestBody MarkdownDto markdownDto) {
        return Result.ok(MarkdownUtils.renderMarkdown(markdownDto.getMarkdown()));
    }

    @GetMapping("/alias")
    @Operation(summary = "字符串转换为拼音", description = "字符串转换为拼音")
    public Result<String> alias(@RequestParam(defaultValue = "") String title, @RequestParam(defaultValue = "-") String separator) {
        return Result.ok(PinyinUtil.getPinyin(title, separator));
    }

}
